<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($this->session('isopenvoice')){
	$return['isopenvoice']=$this->session('isopenvoice')!=2?1:0;	
}else{
	$return['isopenvoice']=1;
}
if($_RQ['op']=='main'){
	model('jy_merch/model')->checkworker(1);
	$merch=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
	$category=pdo_get('jy_merch_category',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merch['cateid']),array('pcate','catename'));
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$cashdays=$this->setting['cash_day']?:1;
	$cashtime = mktime(0,0,0,date('m'),date('d')-$cashdays,date('Y'));
	$return['all_money']=pdo_getsum('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status >'=>0),'price');
	$return['lastget_money']=pdo_getsum('jy_liangoods_sendlog',array('clearstatus'=>0,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>4),'price');
	$return['costprice_money']=pdo_getsum('jy_liangoods_sendlog',array('clearstatus'=>0,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>4),'costprice');
	$return['balancemoney']=pdo_getsum('jy_liangoods_balance',array('status'=>3,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid),'money');
	if($return['balancemoney']>0){
		$return['lastget_money'] +=$return['balancemoney'];
	}
	if($return['pluginset']['is_choufee']){
		$get_choufee=$this->model('merch')->get_choufee($return['lastget_money'],$merchid,1,$return['costprice_money']);
		$return['lastget_money']=$return['lastget_money']-$get_choufee['commission_money'];
	}
	$return['yesget_money']=pdo_getsum('jy_liangoods_sendlog',array('clearstatus'=>1,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>4),'price');
	$merch['today_money']=pdo_getsum('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'gettime >'=>$daytime,'status >'=>0),'price');
	$merch['today_costprice']=pdo_getsum('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'gettime >'=>$daytime,'status >'=>0),'costprice');
	if($return['pluginset']['is_choufee']){
		$get_choufee=$this->model('merch')->get_choufee($merch['today_money'],$merchid,1,$merch['today_costprice']);
		$merch['today_money']=$merch['today_money']-$get_choufee['commission_money'];
	}
	$merch['today_num']=pdo_count('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'gettime >'=>$daytime,'status >'=>0));
	$merch['all_money']=pdo_getsum('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status >'=>0),'price');
	$merch['all_costprice']=pdo_getsum('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status >'=>0),'costprice');
	if($return['pluginset']['is_choufee']){
		$get_choufee=$this->model('merch')->get_choufee($merch['all_money'],$merchid,1,$merch['all_costprice']);
		$merch['all_money']=$merch['all_money']-$get_choufee['commission_money'];
	}
	$merch['all_money']=price($merch['all_money']);
	$merch['today_money']=price($merch['today_money']);
	$return['lastget_money']=price($return['lastget_money']);
	$merch['all_num']=pdo_count('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status >'=>0));
	$return['cate']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	foreach($return['cate'] as $k=>&$gv){
		if($item['cateid']==$gv['id']){
			$item['pcateindex']=$k;
		}
	}
	set_html('title','商户中心');
	if($_SESSION['wxapp_id']){
		$tmpid=cfc('wxapp_api')->get_tpl_template_id('17468',[1,2,3,7],'orderget','新配送任务通知','jy_peisong');
		if($tmpid){
			$tmplIds[]=$tmpid;
		}
		$return['tmplIds']=$tmplIds;
	}
	$merch['url']=custom_url('jy_merch/merch//id='.$merchid,true);
	$return['merch']=$merch;
	$return['category']=$category;
	$status1 = pdo_count('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>1));
	$status2 = pdo_count('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>2));
	$status3 = pdo_count('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>3));
	$status4 = pdo_count('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>4));
	$status5= pdo_count('jy_liangoods_sendlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid,'status'=>5));
	$return['statics']=array(
		'status1'=>$status1,
		'status2'=>$status2,
		'status3'=>$status3,
		'status4'=>$status4,
		'status5'=>$status5
	);
	exi($return);
}
if($_RQ['op']=='getnew'){
	$params=array(
		'status'=>0,
		'uniacid'=>$_SESSION['uniacid'],
	);
	$this->session('isopenvoice',1);
	$order=pdo_get('jy_liangoods_sendlog',$params);
	if($order['id']){
	    $last_noticetime= $this->session('last_noticetime');
	    if(!$last_noticetime || $last_noticetime<time()-60){
            $this->model('notice')->notice_newget($order['id']);
            $this->session('last_noticetime',time());
        }
		exi($order);
	}else{
		exi('none');
	}
}
if($_RQ['op']=='setopenvoice'){
	$isopenvoice=$_RQ['isopenvoice'];
	$isopenvoice=$isopenvoice?1:2;
	$this->session('isopenvoice',$isopenvoice);
	exi($return);
}
?>